import { Injectable } from '@nestjs/common';
import axios, { AxiosResponse } from 'axios';
import * as cherrio from 'cheerio';
interface excelDate {
  titles: Array<string>;
  vals: Array<string>;
}
@Injectable()
export class AppService {
  getHello(): string {
    return 'Hello World!';
  }
  async getHtml(): Promise<excelDate> {
    const res: AxiosResponse<string> = await axios.get(
      'http://quotes.money.163.com/f10/zycwzb_600519.html#01c01',
    );
    const $ = cherrio.load(res.data);
    const table = $('.table_bg001.border_box.limit_sale.scr_table')
      .children()
      .children()
      .first()
      .children();
    const titles = [];
    const vals = [];
    table.map(function (i, e) {
      titles.push($(this).text());
    });
    table
      .parent()
      .parent()
      .children()
      .eq(11)
      .children()
      .map(function (i, e) {
        vals.push($(this).text());
      });

    return { titles, vals };
  }
}
